<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html lang="en">

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>LCOV - code analysis - /usr/include/boost/random/uniform_real_distribution.hpp</title>
  <link rel="stylesheet" type="text/css" href="../../../../gcov.css">
</head>

<body>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="title">LCOV - code coverage report</td></tr>
    <tr><td class="ruler"><img src="../../../../glass.png" width=3 height=3 alt=""></td></tr>

    <tr>
      <td width="100%">
        <table cellpadding=1 border=0 width="100%">
          <tr>
            <td width="10%" class="headerItem">Current view:</td>
            <td width="35%" class="headerValue"><a href="../../../../index.html">top level</a> - <a href="index.html">usr/include/boost/random</a> - uniform_real_distribution.hpp<span style="font-size: 80%;"> (source / <a href="uniform_real_distribution.hpp.func-sort-c.html">functions</a>)</span></td>
            <td width="5%"></td>
            <td width="15%"></td>
            <td width="10%" class="headerCovTableHead">Hit</td>
            <td width="10%" class="headerCovTableHead">Total</td>
            <td width="15%" class="headerCovTableHead">Coverage</td>
          </tr>
          <tr>
            <td class="headerItem">Test:</td>
            <td class="headerValue">code analysis</td>
            <td></td>
            <td class="headerItem">Lines:</td>
            <td class="headerCovTableEntry">6</td>
            <td class="headerCovTableEntry">7</td>
            <td class="headerCovTableEntryMed">85.7 %</td>
          </tr>
          <tr>
            <td class="headerItem">Date:</td>
            <td class="headerValue">2020-09-11 22:50:33</td>
            <td></td>
            <td class="headerItem">Functions:</td>
            <td class="headerCovTableEntry">1</td>
            <td class="headerCovTableEntry">2</td>
            <td class="headerCovTableEntryLo">50.0 %</td>
          </tr>
          <tr>
            <td class="headerItem">Legend:</td>
            <td class="headerValueLeg">            Lines:
            <span class="coverLegendCov">hit</span>
            <span class="coverLegendNoCov">not hit</span>
</td>
            <td></td>
          </tr>
          <tr><td><img src="../../../../glass.png" width=3 height=3 alt=""></td></tr>
        </table>
      </td>
    </tr>

    <tr><td class="ruler"><img src="../../../../glass.png" width=3 height=3 alt=""></td></tr>
  </table>

  <table cellpadding=0 cellspacing=0 border=0>
    <tr>
      <td><br></td>
    </tr>
    <tr>
      <td>
<pre class="sourceHeading">          Line data    Source code</pre>
<pre class="source">
<a name="1"><span class="lineNum">       1 </span>            : /* boost random/uniform_real_distribution.hpp header file</a>
<span class="lineNum">       2 </span>            :  *
<span class="lineNum">       3 </span>            :  * Copyright Jens Maurer 2000-2001
<span class="lineNum">       4 </span>            :  * Copyright Steven Watanabe 2011
<span class="lineNum">       5 </span>            :  * Distributed under the Boost Software License, Version 1.0. (See
<span class="lineNum">       6 </span>            :  * accompanying file LICENSE_1_0.txt or copy at
<span class="lineNum">       7 </span>            :  * http://www.boost.org/LICENSE_1_0.txt)
<span class="lineNum">       8 </span>            :  *
<span class="lineNum">       9 </span>            :  * See http://www.boost.org for most recent version including documentation.
<span class="lineNum">      10 </span>            :  *
<span class="lineNum">      11 </span>            :  * $Id$
<span class="lineNum">      12 </span>            :  *
<span class="lineNum">      13 </span>            :  */
<span class="lineNum">      14 </span>            : 
<span class="lineNum">      15 </span>            : #ifndef BOOST_RANDOM_UNIFORM_REAL_DISTRIBUTION_HPP
<span class="lineNum">      16 </span>            : #define BOOST_RANDOM_UNIFORM_REAL_DISTRIBUTION_HPP
<span class="lineNum">      17 </span>            : 
<span class="lineNum">      18 </span>            : #include &lt;iosfwd&gt;
<span class="lineNum">      19 </span>            : #include &lt;ios&gt;
<span class="lineNum">      20 </span>            : #include &lt;istream&gt;
<span class="lineNum">      21 </span>            : #include &lt;boost/assert.hpp&gt;
<span class="lineNum">      22 </span>            : #include &lt;boost/config.hpp&gt;
<span class="lineNum">      23 </span>            : #include &lt;boost/random/detail/config.hpp&gt;
<span class="lineNum">      24 </span>            : #include &lt;boost/random/detail/operators.hpp&gt;
<span class="lineNum">      25 </span>            : #include &lt;boost/random/detail/signed_unsigned_tools.hpp&gt;
<span class="lineNum">      26 </span>            : #include &lt;boost/type_traits/is_integral.hpp&gt;
<span class="lineNum">      27 </span>            : #include &lt;boost/mpl/bool.hpp&gt;
<span class="lineNum">      28 </span>            : 
<span class="lineNum">      29 </span>            : namespace boost {
<span class="lineNum">      30 </span>            : namespace random {
<span class="lineNum">      31 </span>            : namespace detail {
<span class="lineNum">      32 </span>            : 
<span class="lineNum">      33 </span>            : template&lt;class Engine, class T&gt;
<span class="lineNum">      34 </span>            : T generate_uniform_real(
<span class="lineNum">      35 </span>            :     Engine&amp; eng, T min_value, T max_value,
<span class="lineNum">      36 </span>            :     boost::mpl::false_  /** is_integral&lt;Engine::result_type&gt; */)
<span class="lineNum">      37 </span>            : {
<span class="lineNum">      38 </span>            :     for(;;) {
<span class="lineNum">      39 </span>            :         typedef T result_type;
<span class="lineNum">      40 </span>            :         result_type numerator = static_cast&lt;T&gt;(eng() - (eng.min)());
<span class="lineNum">      41 </span>            :         result_type divisor = static_cast&lt;T&gt;((eng.max)() - (eng.min)());
<span class="lineNum">      42 </span>            :         BOOST_ASSERT(divisor &gt; 0);
<span class="lineNum">      43 </span>            :         BOOST_ASSERT(numerator &gt;= 0 &amp;&amp; numerator &lt;= divisor);
<span class="lineNum">      44 </span>            :         T result = numerator / divisor * (max_value - min_value) + min_value;
<span class="lineNum">      45 </span>            :         if(result &lt; max_value) return result;
<span class="lineNum">      46 </span>            :     }
<span class="lineNum">      47 </span>            : }
<span class="lineNum">      48 </span>            : 
<span class="lineNum">      49 </span>            : template&lt;class Engine, class T&gt;
<span class="lineNum">      50 </span>            : T generate_uniform_real(
<span class="lineNum">      51 </span>            :     Engine&amp; eng, T min_value, T max_value,
<span class="lineNum">      52 </span>            :     boost::mpl::true_  /** is_integral&lt;Engine::result_type&gt; */)
<span class="lineNum">      53 </span>            : {
<span class="lineNum">      54 </span>            :     for(;;) {
<span class="lineNum">      55 </span>            :         typedef T result_type;
<span class="lineNum">      56 </span>            :         typedef typename Engine::result_type base_result;
<span class="lineNum">      57 </span><span class="lineCov">     861000 :         result_type numerator = static_cast&lt;T&gt;(subtract&lt;base_result&gt;()(eng(), (eng.min)()));</span>
<span class="lineNum">      58 </span>            :         result_type divisor = static_cast&lt;T&gt;(subtract&lt;base_result&gt;()((eng.max)(), (eng.min)())) + 1;
<span class="lineNum">      59 </span>            :         BOOST_ASSERT(divisor &gt; 0);
<span class="lineNum">      60 </span>            :         BOOST_ASSERT(numerator &gt;= 0 &amp;&amp; numerator &lt;= divisor);
<span class="lineNum">      61 </span><span class="lineCov">     861000 :         T result = numerator / divisor * (max_value - min_value) + min_value;</span>
<span class="lineNum">      62 </span><span class="lineCov">     861000 :         if(result &lt; max_value) return result;</span>
<span class="lineNum">      63 </span>            :     }
<span class="lineNum">      64 </span>            : }
<a name="65"><span class="lineNum">      65 </span>            : </a>
<span class="lineNum">      66 </span>            : template&lt;class Engine, class T&gt;
<span class="lineNum">      67 </span><span class="lineCov">     861000 : inline T generate_uniform_real(Engine&amp; eng, T min_value, T max_value)</span>
<span class="lineNum">      68 </span>            : {
<span class="lineNum">      69 </span><span class="lineCov">     861000 :     if(max_value / 2 - min_value / 2 &gt; (std::numeric_limits&lt;T&gt;::max)() / 2)</span>
<span class="lineNum">      70 </span><span class="lineNoCov">          0 :         return 2 * generate_uniform_real(eng, min_value / 2, max_value / 2);</span>
<span class="lineNum">      71 </span>            :     typedef typename Engine::result_type base_result;
<span class="lineNum">      72 </span>            :     return generate_uniform_real(eng, min_value, max_value,
<span class="lineNum">      73 </span>            :         boost::is_integral&lt;base_result&gt;());
<span class="lineNum">      74 </span>            : }
<span class="lineNum">      75 </span>            : 
<span class="lineNum">      76 </span>            : }
<span class="lineNum">      77 </span>            : 
<span class="lineNum">      78 </span>            : /**
<span class="lineNum">      79 </span>            :  * The class template uniform_real_distribution models a \random_distribution.
<span class="lineNum">      80 </span>            :  * On each invocation, it returns a random floating-point value uniformly
<span class="lineNum">      81 </span>            :  * distributed in the range [min..max).
<span class="lineNum">      82 </span>            :  */
<span class="lineNum">      83 </span>            : template&lt;class RealType = double&gt;
<span class="lineNum">      84 </span>            : class uniform_real_distribution
<span class="lineNum">      85 </span>            : {
<span class="lineNum">      86 </span>            : public:
<span class="lineNum">      87 </span>            :     typedef RealType input_type;
<span class="lineNum">      88 </span>            :     typedef RealType result_type;
<span class="lineNum">      89 </span>            : 
<span class="lineNum">      90 </span>            :     class param_type
<span class="lineNum">      91 </span>            :     {
<span class="lineNum">      92 </span>            :     public:
<span class="lineNum">      93 </span>            : 
<span class="lineNum">      94 </span>            :         typedef uniform_real_distribution distribution_type;
<span class="lineNum">      95 </span>            : 
<span class="lineNum">      96 </span>            :         /**
<span class="lineNum">      97 </span>            :          * Constructs the parameters of a uniform_real_distribution.
<span class="lineNum">      98 </span>            :          *
<span class="lineNum">      99 </span>            :          * Requires min &lt;= max
<span class="lineNum">     100 </span>            :          */
<span class="lineNum">     101 </span>            :         explicit param_type(RealType min_arg = RealType(0.0),
<span class="lineNum">     102 </span>            :                             RealType max_arg = RealType(1.0))
<span class="lineNum">     103 </span>            :           : _min(min_arg), _max(max_arg)
<span class="lineNum">     104 </span>            :         {
<span class="lineNum">     105 </span>            :             BOOST_ASSERT(_min &lt; _max);
<span class="lineNum">     106 </span>            :         }
<span class="lineNum">     107 </span>            : 
<span class="lineNum">     108 </span>            :         /** Returns the minimum value of the distribution. */
<span class="lineNum">     109 </span>            :         RealType a() const { return _min; }
<span class="lineNum">     110 </span>            :         /** Returns the maximum value of the distribution. */
<span class="lineNum">     111 </span>            :         RealType b() const { return _max; }
<span class="lineNum">     112 </span>            : 
<span class="lineNum">     113 </span>            :         /** Writes the parameters to a @c std::ostream. */
<span class="lineNum">     114 </span>            :         BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR(os, param_type, parm)
<span class="lineNum">     115 </span>            :         {
<span class="lineNum">     116 </span>            :             os &lt;&lt; parm._min &lt;&lt; &quot; &quot; &lt;&lt; parm._max;
<span class="lineNum">     117 </span>            :             return os;
<span class="lineNum">     118 </span>            :         }
<span class="lineNum">     119 </span>            : 
<span class="lineNum">     120 </span>            :         /** Reads the parameters from a @c std::istream. */
<span class="lineNum">     121 </span>            :         BOOST_RANDOM_DETAIL_ISTREAM_OPERATOR(is, param_type, parm)
<span class="lineNum">     122 </span>            :         {
<span class="lineNum">     123 </span>            :             RealType min_in, max_in;
<span class="lineNum">     124 </span>            :             if(is &gt;&gt; min_in &gt;&gt; std::ws &gt;&gt; max_in) {
<span class="lineNum">     125 </span>            :                 if(min_in &lt;= max_in) {
<span class="lineNum">     126 </span>            :                     parm._min = min_in;
<span class="lineNum">     127 </span>            :                     parm._max = max_in;
<span class="lineNum">     128 </span>            :                 } else {
<span class="lineNum">     129 </span>            :                     is.setstate(std::ios_base::failbit);
<span class="lineNum">     130 </span>            :                 }
<span class="lineNum">     131 </span>            :             }
<span class="lineNum">     132 </span>            :             return is;
<span class="lineNum">     133 </span>            :         }
<span class="lineNum">     134 </span>            : 
<span class="lineNum">     135 </span>            :         /** Returns true if the two sets of parameters are equal. */
<span class="lineNum">     136 </span>            :         BOOST_RANDOM_DETAIL_EQUALITY_OPERATOR(param_type, lhs, rhs)
<span class="lineNum">     137 </span>            :         { return lhs._min == rhs._min &amp;&amp; lhs._max == rhs._max; }
<span class="lineNum">     138 </span>            : 
<span class="lineNum">     139 </span>            :         /** Returns true if the two sets of parameters are different. */
<span class="lineNum">     140 </span>            :         BOOST_RANDOM_DETAIL_INEQUALITY_OPERATOR(param_type)
<span class="lineNum">     141 </span>            : 
<span class="lineNum">     142 </span>            :     private:
<span class="lineNum">     143 </span>            : 
<span class="lineNum">     144 </span>            :         RealType _min;
<span class="lineNum">     145 </span>            :         RealType _max;
<span class="lineNum">     146 </span>            :     };
<span class="lineNum">     147 </span>            : 
<span class="lineNum">     148 </span>            :     /**
<span class="lineNum">     149 </span>            :      * Constructs a uniform_real_distribution. @c min and @c max are
<span class="lineNum">     150 </span>            :      * the parameters of the distribution.
<span class="lineNum">     151 </span>            :      *
<span class="lineNum">     152 </span>            :      * Requires: min &lt;= max
<span class="lineNum">     153 </span>            :      */
<span class="lineNum">     154 </span>            :     explicit uniform_real_distribution(
<span class="lineNum">     155 </span>            :         RealType min_arg = RealType(0.0),
<span class="lineNum">     156 </span>            :         RealType max_arg = RealType(1.0))
<span class="lineNum">     157 </span>            :       : _min(min_arg), _max(max_arg)
<span class="lineNum">     158 </span>            :     {
<span class="lineNum">     159 </span>            :         BOOST_ASSERT(min_arg &lt; max_arg);
<span class="lineNum">     160 </span>            :     }
<span class="lineNum">     161 </span>            :     /** Constructs a uniform_real_distribution from its parameters. */
<span class="lineNum">     162 </span>            :     explicit uniform_real_distribution(const param_type&amp; parm)
<span class="lineNum">     163 </span>            :       : _min(parm.a()), _max(parm.b()) {}
<span class="lineNum">     164 </span>            : 
<span class="lineNum">     165 </span>            :     /**  Returns the minimum value of the distribution */
<span class="lineNum">     166 </span>            :     RealType min BOOST_PREVENT_MACRO_SUBSTITUTION () const { return _min; }
<span class="lineNum">     167 </span>            :     /**  Returns the maximum value of the distribution */
<span class="lineNum">     168 </span>            :     RealType max BOOST_PREVENT_MACRO_SUBSTITUTION () const { return _max; }
<span class="lineNum">     169 </span>            : 
<span class="lineNum">     170 </span>            :     /**  Returns the minimum value of the distribution */
<span class="lineNum">     171 </span>            :     RealType a() const { return _min; }
<span class="lineNum">     172 </span>            :     /**  Returns the maximum value of the distribution */
<span class="lineNum">     173 </span>            :     RealType b() const { return _max; }
<span class="lineNum">     174 </span>            : 
<span class="lineNum">     175 </span>            :     /** Returns the parameters of the distribution. */
<span class="lineNum">     176 </span>            :     param_type param() const { return param_type(_min, _max); }
<span class="lineNum">     177 </span>            :     /** Sets the parameters of the distribution. */
<span class="lineNum">     178 </span>            :     void param(const param_type&amp; parm)
<span class="lineNum">     179 </span>            :     {
<span class="lineNum">     180 </span>            :         _min = parm.a();
<span class="lineNum">     181 </span>            :         _max = parm.b();
<span class="lineNum">     182 </span>            :     }
<span class="lineNum">     183 </span>            : 
<span class="lineNum">     184 </span>            :     /**
<span class="lineNum">     185 </span>            :      * Effects: Subsequent uses of the distribution do not depend
<span class="lineNum">     186 </span>            :      * on values produced by any engine prior to invoking reset.
<span class="lineNum">     187 </span>            :      */
<span class="lineNum">     188 </span>            :     void reset() { }
<span class="lineNum">     189 </span>            : 
<span class="lineNum">     190 </span>            :     /** Returns a value uniformly distributed in the range [min, max). */
<span class="lineNum">     191 </span>            :     template&lt;class Engine&gt;
<span class="lineNum">     192 </span>            :     result_type operator()(Engine&amp; eng) const
<span class="lineNum">     193 </span><span class="lineCov">     861000 :     { return detail::generate_uniform_real(eng, _min, _max); }</span>
<span class="lineNum">     194 </span>            : 
<span class="lineNum">     195 </span>            :     /**
<span class="lineNum">     196 </span>            :      * Returns a value uniformly distributed in the range
<span class="lineNum">     197 </span>            :      * [param.a(), param.b()).
<span class="lineNum">     198 </span>            :      */
<span class="lineNum">     199 </span>            :     template&lt;class Engine&gt;
<span class="lineNum">     200 </span>            :     result_type operator()(Engine&amp; eng, const param_type&amp; parm) const
<span class="lineNum">     201 </span>            :     { return detail::generate_uniform_real(eng, parm.a(), parm.b()); }
<span class="lineNum">     202 </span>            : 
<span class="lineNum">     203 </span>            :     /** Writes the distribution to a @c std::ostream. */
<span class="lineNum">     204 </span>            :     BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR(os, uniform_real_distribution, ud)
<span class="lineNum">     205 </span>            :     {
<span class="lineNum">     206 </span>            :         os &lt;&lt; ud.param();
<span class="lineNum">     207 </span>            :         return os;
<span class="lineNum">     208 </span>            :     }
<span class="lineNum">     209 </span>            : 
<span class="lineNum">     210 </span>            :     /** Reads the distribution from a @c std::istream. */
<span class="lineNum">     211 </span>            :     BOOST_RANDOM_DETAIL_ISTREAM_OPERATOR(is, uniform_real_distribution, ud)
<span class="lineNum">     212 </span>            :     {
<span class="lineNum">     213 </span>            :         param_type parm;
<span class="lineNum">     214 </span>            :         if(is &gt;&gt; parm) {
<span class="lineNum">     215 </span>            :             ud.param(parm);
<span class="lineNum">     216 </span>            :         }
<span class="lineNum">     217 </span>            :         return is;
<span class="lineNum">     218 </span>            :     }
<span class="lineNum">     219 </span>            : 
<span class="lineNum">     220 </span>            :     /**
<span class="lineNum">     221 </span>            :      * Returns true if the two distributions will produce identical sequences
<span class="lineNum">     222 </span>            :      * of values given equal generators.
<span class="lineNum">     223 </span>            :      */
<span class="lineNum">     224 </span>            :     BOOST_RANDOM_DETAIL_EQUALITY_OPERATOR(uniform_real_distribution, lhs, rhs)
<span class="lineNum">     225 </span>            :     { return lhs._min == rhs._min &amp;&amp; lhs._max == rhs._max; }
<span class="lineNum">     226 </span>            :     
<span class="lineNum">     227 </span>            :     /**
<span class="lineNum">     228 </span>            :      * Returns true if the two distributions may produce different sequences
<span class="lineNum">     229 </span>            :      * of values given equal generators.
<span class="lineNum">     230 </span>            :      */
<span class="lineNum">     231 </span>            :     BOOST_RANDOM_DETAIL_INEQUALITY_OPERATOR(uniform_real_distribution)
<span class="lineNum">     232 </span>            : 
<span class="lineNum">     233 </span>            : private:
<span class="lineNum">     234 </span>            :     RealType _min;
<span class="lineNum">     235 </span>            :     RealType _max;
<span class="lineNum">     236 </span>            : };
<span class="lineNum">     237 </span>            : 
<span class="lineNum">     238 </span>            : } // namespace random
<span class="lineNum">     239 </span>            : } // namespace boost
<span class="lineNum">     240 </span>            : 
<span class="lineNum">     241 </span>            : #endif // BOOST_RANDOM_UNIFORM_INT_HPP
</pre>
      </td>
    </tr>
  </table>
  <br>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="ruler"><img src="../../../../glass.png" width=3 height=3 alt=""></td></tr>
    <tr><td class="versionInfo">Generated by: <a href="http://ltp.sourceforge.net/coverage/lcov.php" target="_parent">LCOV version 1.12</a></td></tr>
  </table>
  <br>

</body>
</html>
